import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Regex {

	public static void main(String args[]) throws Exception {
		run();
	}

	private static void run() {
		String regex = "(^[\\d]{1,3}[\\.][\\d]{1,3}[\\.][\\d]{1,3}[\\.][\\d]{1,3})$";
		Pattern pattern = Pattern.compile(regex);
		String input = "172.123.13.25";
		String[] examples = { input };
		boolean invalid = false;
		for (String ex : examples) {
			Matcher matcher = pattern.matcher(ex);
			while (matcher.find())
				// System.out.println("\"" + ex + "\" is " + (matcher.find() ?
				// "" : "NOT ") + "a match.");
				// System.out.println("hello" + (matcher.find() ? "as" :
				// "Not"));
				if (matcher.matches()) {
					String ips[] = ex.split("\\.");
					for (int i = 0; i < ips.length; i++) {
						if (!checkRange(ips[i])) {
							invalid = true;
						}
					}
				}
		}
		if (!invalid) {
			System.out.println("All ok");
		} else if (invalid) {
			System.out.println("Invalid IP adress");
		}
	}

	public static boolean checkRange(String subIP) {
		if (Integer.parseInt(subIP) >= 0 && Integer.parseInt(subIP) < 256) {
			return true;
		}
		return false;
	}
}
